package com.zsc.controller.admin;

import com.zsc.dto.OrdersPageQueryDTO;
import com.zsc.entity.Orders;
import com.zsc.result.PageResult;
import com.zsc.result.Result;
import com.zsc.service.OrdersService;
import com.zsc.vo.OrderDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author
 * @Date 2024/6/13 18:53
 */
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "管理端 订单管理接口")
public class OrderController {

    @Autowired
    private OrdersService orderService;

    @GetMapping("/conditionSearch")
    @ApiOperation("分页查询订单")
    public Result<PageResult> page(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult pageResult = orderService.pageQuery(ordersPageQueryDTO);
        return Result.success(pageResult);
    }


    @GetMapping("/details/{id}")
    @ApiOperation("查询订单详情")
    public Result<OrderDetailVO> getdetails(@PathVariable("id") Long id) {
        OrderDetailVO orderDetailVO = orderService.OrderDetails(id);
        return Result.success(orderDetailVO);
    }


    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result<String> finish(@PathVariable("id") long id) {
        try {
            Orders order = orderService.getById(id);
            order.setStatus(1);
            orderService.updateById(order);
            return Result.success("设置订单状态成功");
        } catch (Exception e) {
            return Result.error("设置订单状态失败！！！");
        }
    }

}
